{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import torch\n",
    "import torch.nn as nn\n",
    "import torch.nn.functional as F\n",
    "import torch.optim as optim\n",
    "from torchvision import datasets,transforms\n",
    "from torch.autograd import Variable\n",
    "import matplotlib.pyplot as plt\n",
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "is_cuda=False\n",
    "if torch.cuda.is_available():\n",
    "    is_cuda = True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "transformation = transforms.Compose([transforms.ToTensor(),transforms.Normalize((0.1307,), (0.3081,))])\n",
    "\n",
    "train_dataset = datasets.MNIST('data/',train=True,transform=transformation,download=True)\n",
    "test_dataset = datasets.MNIST('data/',train=False,transform=transformation,download=True)\n",
    "\n",
    "train_loader = torch.utils.data.DataLoader(train_dataset,batch_size=32,shuffle=True)\n",
    "test_loader = torch.utils.data.DataLoader(test_dataset,batch_size=32,shuffle=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "sample_data = next(iter(train_loader))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "def plot_img(image):\n",
    "    image = image.numpy()[0]\n",
    "    mean = 0.1307\n",
    "    std = 0.3081\n",
    "    image = ((mean * image) + std)\n",
    "    plt.imshow(image,cmap='gray')\n",
    "    \n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAP8AAAD8CAYAAAC4nHJkAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AA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35fmo6jXkt0t61cy2m9lA1c1Mo2fKyEhjknqqbGYauSM3d9KXRpauzXvX\nyojXReMDv69a7O4LJd0s6UfZ7m0t+eQxW51O1/xM0nxNDuN2QNLqKpvJRpZ+UdIKd//T1FqV7900\nfVXyvlUR/v2SLpzy/JvZtFpw9/3Z70OSfq3Jw5Q6OXhikNTs96GK+/k/7n7Q3Y+7+4Skn6vC9y4b\nWfpFSevd/aVscuXv3XR9VfW+VRH+IUmXmNm3zGyOpO9L2lRBH19hZqdnH8TIzE6X9B3Vb/ThTZKW\nZo+XStpYYS9/oS4jNzcaWVoVv3e1G/Ha3Tv+I2mJJj/x/x9J/1xFDw36mi/p7ezn3ap7k/ScJncD\nP9fkZyM/kPTXkrZK2iPpVUln16i3ZzQ5mvM7mgza3Ip6W6zJXfp3JO3MfpZU/d4l+qrkfeMbfkBQ\nfOAHBEX4gaAIPxAU4QeCIvxAUIQfCIrwA0ERfiCo/wWm5o6t6bqaegAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7fc64f9c6f98>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plot_img(sample_data[0][2])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAP8AAAD8CAYAAAC4nHJkAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAADXBJREFUeJzt3X+oXPWZx/HPR01RjJJk44Zo4xohCFXByPUHrkhl1+JK\nMQZBG0FSDL0VusFAFMUFN38IGukP+lc1pbFRuqYLbTVocTE3Sra4lPwg1Ri3xtUrSYiJxUoSRWOS\nZ/+4R7nVzHduZs7MmevzfsHlzpzn/HgY7ueeM+fMnK8jQgDyOanpBgA0g/ADSRF+ICnCDyRF+IGk\nCD+QFOEHkiL8QFKEH0jqlH5uzDYfJwR6LCI8kfm62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BFJOyWtlzRjgHp7UmOjOb+isaDNbqi3qzV2SP+KpG3Vzw1Nv3aFvhp5\n3fiEH5AUJ/yApAg/kBThB5Ii/EBShB9IivADSRF+ICnCDyT1/0UJVyJYTcgAAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7fc6ca4120b8>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plot_img(sample_data[0][1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 110,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "class Net(nn.Module):\n",
    "    def __init__(self):\n",
    "        super().__init__()\n",
    "        self.conv1 = nn.Conv2d(1, 10, kernel_size=5)\n",
    "        self.conv2 = nn.Conv2d(10, 20, kernel_size=5)\n",
    "        self.conv2_drop = nn.Dropout2d()\n",
    "        self.fc1 = nn.Linear(320, 50)\n",
    "        self.fc2 = nn.Linear(50, 10)\n",
    "\n",
    "    def forward(self, x):\n",
    "        x = F.relu(F.max_pool2d(self.conv1(x), 2))\n",
    "        x = F.relu(F.max_pool2d(self.conv2_drop(self.conv2(x)), 2))\n",
    "        x = x.view(-1, 320)\n",
    "        x = F.relu(self.fc1(x))\n",
    "        #x = F.dropout(x,p=0.1, training=self.training)\n",
    "        x = self.fc2(x)\n",
    "        return F.log_softmax(x,dim=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 111,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "model = Net()\n",
    "if is_cuda:\n",
    "    model.cuda()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 112,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "optimizer = optim.SGD(model.parameters(),lr=0.01)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 113,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "data , target = next(iter(train_loader))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 114,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "output = model(Variable(data.cuda()))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 115,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "torch.Size([32, 10])"
      ]
     },
     "execution_count": 115,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "output.size()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 116,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "torch.Size([32])"
      ]
     },
     "execution_count": 116,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "target.size()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 117,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "def fit(epoch,model,data_loader,phase='training',volatile=False):\n",
    "    if phase == 'training':\n",
    "        model.train()\n",
    "    if phase == 'validation':\n",
    "        model.eval()\n",
    "        volatile=True\n",
    "    running_loss = 0.0\n",
    "    running_correct = 0\n",
    "    for batch_idx , (data,target) in enumerate(data_loader):\n",
    "        if is_cuda:\n",
    "            data,target = data.cuda(),target.cuda()\n",
    "        data , target = Variable(data,volatile),Variable(target)\n",
    "        if phase == 'training':\n",
    "            optimizer.zero_grad()\n",
    "        output = model(data)\n",
    "        loss = F.nll_loss(output,target)\n",
    "        \n",
    "        running_loss += F.nll_loss(output,target,size_average=False).data[0]\n",
    "        preds = output.data.max(dim=1,keepdim=True)[1]\n",
    "        running_correct += preds.eq(target.data.view_as(preds)).cpu().sum()\n",
    "        if phase == 'training':\n",
    "            loss.backward()\n",
    "            optimizer.step()\n",
    "    \n",
    "    loss = running_loss/len(data_loader.dataset)\n",
    "    accuracy = 100. * running_correct/len(data_loader.dataset)\n",
    "    \n",
    "    print(f'{phase} loss is {loss:{5}.{2}} and {phase} accuracy is {running_correct}/{len(data_loader.dataset)}{accuracy:{10}.{4}}')\n",
    "    return loss,accuracy"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 118,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "training loss is  0.57 and training accuracy is 49446/60000     82.41\n",
      "validation loss is  0.16 and validation accuracy is 9502/10000     95.02\n",
      "training loss is   0.2 and training accuracy is 56571/60000     94.28\n",
      "validation loss is  0.09 and validation accuracy is 9705/10000     97.05\n",
      "training loss is  0.15 and training accuracy is 57471/60000     95.78\n",
      "validation loss is 0.066 and validation accuracy is 9783/10000     97.83\n",
      "training loss is  0.12 and training accuracy is 57865/60000     96.44\n",
      "validation loss is 0.068 and validation accuracy is 9781/10000     97.81\n",
      "training loss is  0.11 and training accuracy is 58032/60000     96.72\n",
      "validation loss is 0.052 and validation accuracy is 9826/10000     98.26\n",
      "training loss is   0.1 and training accuracy is 58190/60000     96.98\n",
      "validation loss is 0.046 and validation accuracy is 9848/10000     98.48\n",
      "training loss is 0.091 and training accuracy is 58407/60000     97.34\n",
      "validation loss is 0.043 and validation accuracy is 9869/10000     98.69\n",
      "training loss is 0.085 and training accuracy is 58517/60000     97.53\n",
      "validation loss is 0.047 and validation accuracy is 9843/10000     98.43\n",
      "training loss is 0.079 and training accuracy is 58581/60000     97.64\n",
      "validation loss is 0.044 and validation accuracy is 9855/10000     98.55\n",
      "training loss is 0.075 and training accuracy is 58649/60000     97.75\n",
      "validation loss is 0.039 and validation accuracy is 9868/10000     98.68\n",
      "training loss is 0.069 and training accuracy is 58752/60000     97.92\n",
      "validation loss is 0.034 and validation accuracy is 9888/10000     98.88\n",
      "training loss is 0.069 and training accuracy is 58791/60000     97.98\n",
      "validation loss is 0.033 and validation accuracy is 9893/10000     98.93\n",
      "training loss is 0.066 and training accuracy is 58844/60000     98.07\n",
      "validation loss is 0.032 and validation accuracy is 9897/10000     98.97\n",
      "training loss is 0.064 and training accuracy is 58818/60000     98.03\n",
      "validation loss is  0.03 and validation accuracy is 9907/10000     99.07\n",
      "training loss is 0.061 and training accuracy is 58916/60000     98.19\n",
      "validation loss is 0.033 and validation accuracy is 9893/10000     98.93\n",
      "training loss is 0.059 and training accuracy is 58973/60000     98.29\n",
      "validation loss is 0.033 and validation accuracy is 9889/10000     98.89\n",
      "training loss is 0.058 and training accuracy is 58948/60000     98.25\n",
      "validation loss is 0.031 and validation accuracy is 9900/10000      99.0\n",
      "training loss is 0.056 and training accuracy is 59000/60000     98.33\n",
      "validation loss is  0.03 and validation accuracy is 9903/10000     99.03\n",
      "training loss is 0.055 and training accuracy is 59011/60000     98.35\n",
      "validation loss is 0.028 and validation accuracy is 9906/10000     99.06\n"
     ]
    }
   ],
   "source": [
    "train_losses , train_accuracy = [],[]\n",
    "val_losses , val_accuracy = [],[]\n",
    "for epoch in range(1,20):\n",
    "    epoch_loss, epoch_accuracy = fit(epoch,model,train_loader,phase='training')\n",
    "    val_epoch_loss , val_epoch_accuracy = fit(epoch,model,test_loader,phase='validation')\n",
    "    train_losses.append(epoch_loss)\n",
    "    train_accuracy.append(epoch_accuracy)\n",
    "    val_losses.append(val_epoch_loss)\n",
    "    val_accuracy.append(val_epoch_accuracy)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 119,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.legend.Legend at 0x7fc6c153cba8>"
      ]
     },
     "execution_count": 119,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXcAAAD8CAYAAACMwORRAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAH4VJREFUeJzt3X10VPW97/H3lyQQw7OAB3kwwRYrhGciotSiS9sLqFCs\nD1i8lVaLeLTW5dErt7Zo7aHVe63l0IO6sNX2alpFFGstLFq6sOg5PhAQ8VlBAgQKBCRAeMZ87x97\nkkzCTDIkk8zM5vNaa6/Zs/dvZn+zGT57z2/2g7k7IiISLm1SXYCIiCSfwl1EJIQU7iIiIaRwFxEJ\nIYW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+ocyz137lyGDh3K6NGj2bx5M59++ulxr+nXrx/Dhg0DYOTIkZSWlsZ87yuuuOK4Nq+9\n9hpTpkwBYNy4cXTt2rXB+l577TUmT55M+/bt6dChA1dccQWvvvoqgwcP5m9/+xt33303r776Kp07\nd6Zz587k5uZyww038MILL5BXv7uhFWVUuItI62mt37nat29fM/7KK6+wbNkyXn/9dd555x2GDx8e\n81jvdu3a1YxnZWXF7a+vbtdQm6Y666yzWL16NYMHD+bHP/4x999/P9nZ2bz11ltceeWVvPzyy4wb\nNy6pyzwRCncRiaklfufq2LEj+/btizt/z549dO3alby8PD766CPeeOONpi8sjjFjxrBgwQIA/vrX\nv7J79+4G219wwQW8+OKLHDhwgP3797No0SIuuOACtm7dSl5eHtdddx133XUXq1evprKykj179jBh\nwgR+9atf8c477yS9/kRlzElMItK6qrs977kn6Io544wg2JvTHdqtWzfGjBnDoEGDGD9+PJdeemmd\n+ePGjeOxxx5jwIABfOUrX2H06NHN+Atiu/fee7n22mt56qmnOO+88+jZsycdO3aM237EiBFMmzaN\nUaNGAXDjjTcyfPhwli5dyl133UWbNm3Iycnh0UcfZd++fUyaNIlDhw7h7jz88MNJrz9RFvTPt76i\noiLXzTpEWteHH37IgAEDUl1GSh0+fJisrCyys7N5/fXXufnmm1mzZk2qy4op1r+Xma1y96LGXqs9\ndxE5qWzatImrr76aqqoq2rZty+OPP57qklqEwl1ETir9+/fn7bffTnUZLU4/qIqIhJDCXUQkhBTu\nIiIhpHAXEQkhhbuIpLUOHToAsHXrVq688sqYbS688EIaO7R6zpw5HIi6KUQilxBOxH333cdDDz3U\n7PdJNoW7iGSEXr161VzxsSnqh3silxDOZAp3EWk1M2fOZN68eTXPq/d6Kysrufjii2suz/unP/3p\nuNeWlpYyaNAgAA4ePMiUKVMYMGAAkydPrrnkL8DNN99MUVERhYWF3HvvvUBwMbKtW7dy0UUXcdFF\nFwF1b8YR65K+DV1aOJ41a9YwevRohgwZwuTJk2subTB37tyaywBXX7TsH//4B8OGDWP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fDHllp+Kpz04R7NzAqA4cCbMWafH/k6vMTMClu1sFoOLDOz\nVWY2Pcb83sDmqOdlpHZDNYX4/2HSYX1W+xd3/2dkfBvwLzHapNu6/R7Bt7RYGvuctIYfRP59n4jT\nzZVO6/MCYLu7fxpnfjqszxOmcI8wsw7A88Dt7r633uzVwBnuPgT4NfBia9cX8VV3HwaMB24xs6+l\nqI5GmVlbYCLwXIzZ6bI+j+PB9/C0PoTMzO4BjgHFcZqk+nPyKEF3yzDgnwRdHunsWhrea0/1+mwS\nhTtgZjkEwV7s7i/Un+/ue929MjK+GMgxs+6tXCbuviXyuANYRPDVNtoWoG/U8z6RaakwHljt7tvr\nz0iX9Rlle3X3VeRxR4w2abFuzWwacBkwNbIhOk4Cn5MW5e7b3f0Ld68CHo+z/HRZn9nAFcCz8dqk\nen021Ukf7pH+tt8CH7r7w3Ha9Iy0w8xGEay3Xa1XJZhZezPrWD1O8OPae/WavQR8J3LUzGhgT1R3\nQ2uLuzeUDuuznpeA6yPj1wN/itFmJdDfzPpFvpVMibyu1ZjZOOB/ARPd/UCcNol8TlpUvd95JsdZ\nfsrXZ8QlwEfuXhZrZjqszyZL9S+6qR6ArxJ8DV8LrIkME4AZwIxIm1uB9wl+0X8DOD8FdZ4ZWf47\nkVruiUyPrtOAeQRHIbwLFKVonbYnCOvOUdPSYn0SbHD+CRwl6Oe9AegG/B34FFgGnBpp2wtYHPXa\nCQRHU62vXv+tXOc6gn7q6s/pY/XrjPc5aeU6n4p8/tYSBPbp6bg+I9N/V/25jGqbsvWZzEFnqIqI\nhNBJ3y0jIhJGCncRkRBSuIuIhJDCXUQkhBTuIiIhpHAXEQkhhbuISAgp3EVEQuj/A6pUY1X4Joal\nAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7fc6c16d4f28>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.plot(range(1,len(train_losses)+1),train_losses,'bo',label = 'training loss')\n",
    "plt.plot(range(1,len(val_losses)+1),val_losses,'r',label = 'validation loss')\n",
    "plt.legend()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 120,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.legend.Legend at 0x7fc6c14cb358>"
      ]
     },
     "execution_count": 120,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAX4AAAD8CAYAAABw1c+bAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3Xt8VPWd//HXB8LFIGKAgNyS0BVRAoRLRBbFYhVX0VrF\nBwst3rDKz9br7k9ZrHbl8bP+HvWntl2r7RpbqlasuljW2qVeqFrdrRcCBUQBQQkYQAh3FIQEPr8/\nzkwyhJlkkkwyk5z38/E4jzNzrp85hPec+c6Z7zF3R0REwqNdugsQEZGWpeAXEQkZBb+ISMgo+EVE\nQkbBLyISMgp+EZGQUfCLiISMgl9EJGQU/CIiIZOV7gLi6dmzpxcUFKS7DBGRVmPJkiXb3T03mWUz\nMvgLCgooLS1NdxkiIq2GmW1Idlk19YiIhIyCX0QkZBT8IiIho+AXEQkZBb+ISMgo+EVEQkbBLyIS\nMhl5Hb+IZIiqKti1C3buPHbYswdycqBPn6OH445Ld9Utyz04TpWVcOhQMI59HG9aovkdOsD06c1e\nsoJfpK04cgQOHoSvvgrG0aH28+i03bsTh3p02Lu34XWceOKxbwZ9+kDfvkc/79o19ccgnsOHg9e6\nfXvNsGPH0c937w4CuDHBXVmZulp79VLwi7QpO3fCJ58E4wMHGj989VVNmMeGelVV4+pq3x66d68Z\n+vSBwsKjp8UbunYN3ji2bIk/bN4M//M/weODB4/db5cucNJJkJ0NnTrVDJ07H/28rumdO0O7dkEd\niUJ9587grDyeTp2gZ8/gzapTJ+jYMTjr7tQpeH0dOtRMi30cb1p985NZp1Onxv0bNpCCXyRV3KGi\nAtatiz/s2lX/NrKyg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kDp07d6Z///506NCh0duoN/jd/T0z\nmw8sBaqAvwElwK/MbATgQBnwvwDMrC/wK3ef5O5VZnYT8ArB1UBz3f3DRlcrIs2mvLycrl27UlBQ\ngJmluxyJw93ZsWMH5eXlDBw4sNHbSeaMH3e/B7in1uQrEyy7GZgU83whcMylniKSWb766iuFfoYz\nM3r06EFTL4DRL3dFpJpCP/Ol4t9IwS8iGWH37t384he/aNS6kyZNYvfu3SmuqO1S8ItIo8ybBwUF\n0K5dMJ43r2nbqyv4q6qq6lx34cKFnHjiiU0roBm4O0eOHEl3GcdQ8ItIg82bBzNnwoYN4B6MZ85s\nWvjPnj2bTz75hBEjRnDHHXfw5ptvMn78eC655BKGDAl6ern00ksZPXo0hYWFlJSUVK9bUFDA9u3b\nKSsr47TTTuP666+nsLCQ888/nwMHDhyzr5deeokzzjiDkSNHct5557F161YAvvjiC2bMmMGwYcMY\nPnw4L7zwAgAvv/wyo0aNoqioiHPPPReAOXPm8OCDD1Zvc+jQoZSVlVFWVsbgwYO56qqrGDp0KJ99\n9hnf+973KC4uprCwkHvuqfm6dPHixYwbN46ioiLGjBnDvn37OPvss1m2bFn1MmeddRbLly9v/IGN\nx90zbhg9erSLSMv66KOPkl42P989iPyjh/z8xu9//fr1XlhYWP38jTfe8OzsbP/000+rp+3YscPd\n3ffv3++FhYW+ffv2SD35XlFR4evXr/f27dv73/72N3d3nzJliv/2t789Zl87d+70I0eOuLv7448/\n7v/8z//s7u6zZs3yW2+99ajltm3b5v3796+uI1rDPffc4w888ED1soWFhb5+/Xpfv369m5m/8847\nx9RdVVXlX//613358uV+8OBBHzhwoL///vvu7r5nzx6vrKz0J554orqGNWvWeLw8jPdvBZR6khmb\n1FU9IiKxNm5s2PTGGjNmzFGXLT788MMsWLAAgM8++4y1a9fSo0ePo9YZOHAgI0aMAGD06NGUlZUd\ns93y8nKmTp3Kli1bOHToUPU+Fi1axLPPPlu9XE5ODi+99BJnn3129TLdu3evt+78/HzGjh1b/fz5\n55+npKSEqq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AxlGUzI8DePuAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7fc6c9d3e0f0>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.plot(range(1,len(train_accuracy)+1),train_accuracy,'bo',label = 'train accuracy')\n",
    "plt.plot(range(1,len(val_accuracy)+1),val_accuracy,'r',label = 'val accuracy')\n",
    "plt.legend()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Understanding 1d convolutions"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "conv = nn.Conv1d(1,1,3,bias=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Parameter containing:\n",
       "(0 ,.,.) = \n",
       "  0.4587 -0.0157  0.4784\n",
       "[torch.FloatTensor of size 1x1x3]"
      ]
     },
     "execution_count": 72,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "conv.weight"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "sample = torch.randn(1,1,7)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\n",
       "(0 ,.,.) = \n",
       "  0.2512  1.2605  0.4839  1.1320 -0.3045 -0.8963  0.1234\n",
       "[torch.FloatTensor of size 1x1x7]"
      ]
     },
     "execution_count": 74,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sample"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Variable containing:\n",
       "(0 ,.,.) = \n",
       "  0.3268  1.1121  0.0585  0.0953 -0.0666\n",
       "[torch.FloatTensor of size 1x1x5]"
      ]
     },
     "execution_count": 75,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "conv(Variable(sample))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Understand how padding works in Conv1d"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Parameter containing:\n",
       "(0 ,.,.) = \n",
       "  0.1482 -0.4679  0.1801\n",
       "[torch.FloatTensor of size 1x1x3]"
      ]
     },
     "execution_count": 76,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "conv = nn.Conv1d(1,1,3,padding=2,bias=False)\n",
    "conv.weight"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 77,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\n",
       "(0 ,.,.) = \n",
       "  0.6738 -0.1219 -0.9730  0.8453  0.2469 -0.4196  1.0974\n",
       "[torch.FloatTensor of size 1x1x7]"
      ]
     },
     "execution_count": 77,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sample = torch.randn(1,1,7)\n",
    "sample"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 78,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Variable containing:\n",
       "(0 ,.,.) = \n",
       "  0.1213 -0.3373 -0.0183  0.5894 -0.4953 -0.0658  0.4306 -0.5757  0.1627\n",
       "[torch.FloatTensor of size 1x1x9]"
      ]
     },
     "execution_count": 78,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "conv(Variable(sample))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
